import React, { Component } from 'react'

class Demo extends Component {
  handleClick = (params)=> {
    this.props.handlePClick('🐂')
  }
  render() {
    return <div>------
      <h2>Demo 组件</h2>
      <DemoChild msg={this.props.msg}></DemoChild>
      <button onClick={this.handleClick}>传值给兄弟 Test</button><br />
      ------
    </div>
  }
}

class DemoChild extends Component{
  render(){
    return <div>
      --<span>DemoChild 组件</span>--
      App 组件传来的值：{this.props.msg}
    </div>
  }
}

class Test extends Component {
  render() {
    return <div>
      ------
      <h2>Test 组件</h2>
      <h2>接收到兄弟Demo传来的值：{this.props.title}</h2>
      ------
    </div>
  }
}

export default class App extends Component {
  state = {
    title: '',
    msg: '🐖'
  }

  handlePClick = (params) => {
    this.setState({
      title: params
    })
  }

  render() {
    return (
      <div>
        <Demo handlePClick={this.handlePClick} msg={this.state.msg}>
          <DemoChild></DemoChild>
        </Demo>
        <Test title={this.state.title}></Test>
      </div>
    )
  }
}
